/**
 * 
 */
package com.vote.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vote.dao.PrizeInfoDao;
import com.vote.dao.RespondentDao;
import com.vote.entity.PrizeInfo;
import com.vote.entity.Respondent;

//Spring Bean的标识.
@Service
// 默认将类中的所有函数纳入事务管理.
@Transactional
public class PrizeInfoManager{
	
	private static Logger log = LoggerFactory.getLogger(PrizeInfoManager.class);
	@Autowired
	private PrizeInfoDao prizeInfoDao;	
	@Autowired
	private RespondentDao respondentDao;
	
	public void savePrizedUserInfo(Respondent resp){		
		respondentDao.update(resp);		
		PrizeInfo prizeInfo=prizeInfoDao.getPrizeInfoByIPCookie(resp.getIp(),resp.getCookie());
		if(prizeInfo!=null){
			prizeInfo.setMobile(resp.getMobile());
			prizeInfo.setAddress(resp.getAddress());
			prizeInfo.setEmail(resp.getEmail());
			prizeInfo.setUserName(resp.getUserName());
			prizeInfoDao.update(prizeInfo);
			log.info("userName:" + resp.getUserName() 
					+ " mobile:" + resp.getMobile() 
					+ " address:" + resp.getAddress() 
					+ " email:" + resp.getEmail() 
					+ " prized prizeName:"+((prizeInfo.getPrizeSetting()!=null)?(prizeInfo.getPrizeSetting().getPrizeName()):""));
		}		
	}

	public PrizeInfoDao getPrizeInfoDao() {
		return prizeInfoDao;
	}

	public void setPrizeInfoDao(PrizeInfoDao prizeInfoDao) {
		this.prizeInfoDao = prizeInfoDao;
	}

	public RespondentDao getRespondentDao() {
		return respondentDao;
	}

	public void setRespondentDao(RespondentDao respondentDao) {
		this.respondentDao = respondentDao;
	}
	
	
				
}
